#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File Name: charHelper.py
# Author: bobo
# Created Time: 20231223
import re


def contains_chs(input_str):
    """
    判断是否包含中文
    """
    patter = re.compile(r'[\u4e00-\u9fff]')
    result = patter.search(input_str)
    return True if result else False


def isurl(url):
    """
    判断是否为网站地址
    """
    pattern = re.compile(r'^((https|http|ftp|rtsp|mms)?:\/\/)[^\s]+')
    m = pattern.search(url)
    if m is None:
        return False
    else:
        return True


def search_protocol_and_domain(url):
    """
    获取链接的协议和主机名
    """
    pattern = re.compile(r'^(?P<protocol>.*)://(?P<domain>[\S]+?)/[\S]*')
    m = pattern.search(url)
    # print(m)
    if m is None:
        return False, None, None
    else:
        return True, m.group('protocol'), m.group('domain')


def slash_unicode_to_chs(slash_unicode):
    """
    # 把含有"\\uxxx"的字符串转化成中文，并把多余的'\'删除，如："\\/"变为'/'
    """
    res = slash_unicode.encode('utf-8').decode('raw_unicode_escape').replace("\\", '')
    return res
